/*
*  Copyright (c) 2018. 玺得（深圳）科技有限公司.保留所有权利. http://www.pi-top.com/ 玺得（深圳）科技有限公司保留所有代码著作权.如有任何疑问请访问官方网站与我们联系. 代码只针对特定需求定制编码，不得在未经允许或授权的情况下对外传播扩散.恶意传播者，法律后果自行承担. 本代码仅用于pps-cloud系统.
*/
package com.pitop.customer.service;

import com.pitop.core.entity.Page;
import com.pitop.core.exceptions.BaseException;
import com.pitop.core.exceptions.CustomerAddressException;
import com.pitop.customer.api.CustomerAddressFeignApi;
import com.pitop.customer.entity.CustomerAddress;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;


/**
 * 客户地址
 *
 * @author berton
 */
@Service("customerAddressSVImpl")
@Slf4j
public class CustomerAddressSVImpl {

    @Autowired
    private CustomerAddressFeignApi customerAddressFeignApi;

    /**
     * 加载一个对象CustomerAddress
     *
     * @param id * @param customerCode 客户编码
     * @return CustomerAddress
     */
    public CustomerAddress load(Long id, String customerCode) {
        if (id == null && customerCode == null) {
            throw new CustomerAddressException(BaseException.BaseExceptionEnum.Illegal_Param);
        }
        return customerAddressFeignApi.load(id, customerCode);
    }

    /**
     * 加载一个对象CustomerAddress 通过id
     *
     * @param id
     * @return CustomerAddress
     */
    public CustomerAddress loadById(Long id) {
        if (id == null) {
            throw new CustomerAddressException(BaseException.BaseExceptionEnum.Illegal_Param);
        }
        return customerAddressFeignApi.loadById(id);
    }

    /**
     * 加载一个对象CustomerAddress 通过customerCode
     *
     * @param customerCode 客户编码
     * @return CustomerAddress
     */
    public CustomerAddress loadByCustomerCode(String customerCode) {
        if (customerCode == null) {
            throw new CustomerAddressException(BaseException.BaseExceptionEnum.Illegal_Param);
        }
        return customerAddressFeignApi.loadByCustomerCode(customerCode);
    }


    /**
     * 删除对象CustomerAddress
     *
     * @param id * @param customerCode 客户编码
     */

    public void delete(Long id, String customerCode) {
        if (id == null && customerCode == null) {
            throw new CustomerAddressException(BaseException.BaseExceptionEnum.Illegal_Param);
        }
        customerAddressFeignApi.delete(id, customerCode);
    }


    /**
     * 查询CustomerAddress分页
     *
     * @param customerAddress 对象
     * @param curPage         当前页
     * @param pageSize        分页条数
     * @return List<CustomerAddress>
     */
    public List<CustomerAddress> list(CustomerAddress customerAddress, int curPage, int pageSize) {
        return customerAddressFeignApi.list(customerAddress, curPage, pageSize);
    }

    /**
     * 查询CustomerAddress分页
     *
     * @param id       * @param customerCode  客户编码
     * @param curPage  当前页
     * @param pageSize 分页条数
     * @return List<CustomerAddress>
     */
    public List<CustomerAddress> list(Long id, String customerCode, int curPage, int pageSize) {
        if (curPage < 0) {
            curPage = 1;
        }

        if (pageSize < 0) {
            pageSize = Page.limit;
        }

        CustomerAddress customerAddress = new CustomerAddress();
        customerAddress.setId(id);
        customerAddress.setCustomerCode(customerCode);

        return customerAddressFeignApi.list(customerAddress, curPage, pageSize);
    }


    public int count(Long id, String customerCode) {
        return customerAddressFeignApi.count(id, customerCode);
    }


    public int count(CustomerAddress customerAddress) {
        return customerAddressFeignApi.count(customerAddress);
    }


    /**
     * 保存
     *
     * @param customerAddress 实体
     * @throws BaseException
     */
    public void save(CustomerAddress customerAddress) {
        if (customerAddress == null) {
            throw new CustomerAddressException(BaseException.BaseExceptionEnum.Illegal_Param);
        }
        customerAddressFeignApi.build(customerAddress);
    }

    /**
     * 更新
     *
     * @param customerAddress 实体
     * @throws BaseException
     */
    public void modify(CustomerAddress customerAddress) {
        if (customerAddress == null) {
            throw new CustomerAddressException(BaseException.BaseExceptionEnum.Illegal_Param);
        }
        customerAddressFeignApi.modify(customerAddress);
    }

}
